package pojo.dao;

import java.util.List;
import org.apache.ibatis.session.SqlSessionFactory;

import pojo.bean.EmailUser;
import pojo.bean.EmailUserPage;
import pojo.mapper.EmailUserMapper;

public class EmailUserDAO extends AbstractMapperDAO implements EmailUserMapper {
    private EmailUserMapper mapper;
    
    public EmailUserDAO(SqlSessionFactory factory) {
        super(factory);
        mapper = session.getMapper(EmailUserMapper.class);
    }

    @Override
    public int deleteByPrimaryKey(int identifier) {
        try {
            state = mapper.deleteByPrimaryKey(identifier);
            session.commit();
        } catch (Exception e) {
            state = 0;
            e.printStackTrace();
        }
        return state;
    }

    @Override
    public int deleteByPrimaryKeys(List<String> list) {
        try {
            state = mapper.deleteByPrimaryKeys(list);
            session.commit();
        } catch (Exception e) {
            state = 0;
            e.printStackTrace();
        }
        return state;
    }

    @Override
    public int insert(EmailUser record) {
        try {
            state = mapper.insert(record);
            session.commit();
        } catch (Exception e) {
            state = 0;
            e.printStackTrace();
        }
        return state;
    }

    @Override
    public int selectCountByUserNameKeyword(String userName) {
        int recordsCount = 0;
        try {
            recordsCount = mapper.selectCountByUserNameKeyword(userName);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return recordsCount;
    }

    @Override
    public List<EmailUser> selectByUserNameKeyword(EmailUserPage pageBean) {
        List<EmailUser> emailUsers;
        try {
            emailUsers = mapper.selectByUserNameKeyword(pageBean);
        } catch (Exception e) {
            emailUsers = null;
            e.printStackTrace();
        }
        return emailUsers;
    }

    @Override
    public EmailUser selectByPrimaryKey(int identifier) {
        EmailUser emailUser;
        try {
            emailUser = mapper.selectByPrimaryKey(identifier);
        } catch (Exception e) {
            emailUser = null;
            e.printStackTrace();
        }
        return emailUser;
    }

    @Override
    public int updateByPrimaryKey(EmailUser record) {
        try {
            state = mapper.updateByPrimaryKey(record);
            session.commit();
        } catch (Exception e) {
            state = 0;
            e.printStackTrace();
        }
        return state;
    }

}
